package descentFly.app
{
	import UIFree.controls.uif_arrowbutton;
	import UIFree.uif_Timer;
	import UIFree.uif_component;
	import UIFree.uif_draw;
	import UIFree.uif_ecomponent;
	
	import descentFly.app.managePanel.chat.df_chat;
	import descentFly.app.managePanel.chat.df_chatItem;
	import descentFly.app.managePanel.chat.df_turnItem;
	import descentFly.app.managePanel.df_playerInfo;
	import descentFly.app.radar.df_radarPanel;
	import descentFly.app.social.df_defSocial;
	import descentFly.away3D4.df_awaySpace;
	import descentFly.df_utils;
	import descentFly.view.df_view;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import jiglib.debug.Stats;
	
	import space.sp_utils;
	
	public class df_managePanel extends df_panel {
		public static const HEIGHT	: int = 220;
		
		private static const MINLOOKHEIGHT: int = 20;
		private var _hidePos	: int = 0;
		private var _arrow		: uif_arrowbutton;
		
		public function df_managePanel(parent:uif_component, rect: Rectangle, a_styleClass:String='panel') {
			super(parent, rect.x, rect.y, rect.width, HEIGHT, a_styleClass);
		}
		
		override protected function createComponents(layer:df_component, inner:Rectangle):void {
			var space: Number = getSpace(true);
			if (_hidePos > 0) {
				_arrow = new uif_arrowbutton(this, inner.x, inner.y, 20, 14, uif_draw.TOP, 'arrow');
				_arrow.addEvent(MouseEvent.CLICK, doArrowClick);
				inner.left += _arrow.width;
			}
			var res: Array = df_utils.rectDivX(inner, 0.2, space);
			var left: Array = df_utils.rectDivY(res[0], 0.5, space);
			
			if (Space) {
				if (dfApp.params.debug) {
					var a_view: df_view = (app as away_jiglib).view;
					var stats: Stats = new Stats(a_view.view, (Space as df_awaySpace).physic);
					stats.transform.matrix = sp_utils.enterHere(left[1], new Point(182, 126), false);
					layer.addChild(stats);
				}
				new df_playerInfo(layer, left[1], 'playerInfo');
			}
			if (social)
				var _chat: df_chat = new df_chat(layer, social.user, res[1].x, res[1].y, res[1].width, res[1].height);
			
			new df_radarPanel(layer, left[0].x, left[0].y, left[0].width, left[0].height, 'chat');
		}
		
		protected function doArrowClick(e: MouseEvent): void {
			var inner: Rectangle = parentComponent.getInner();
			if (_arrow.orientation == uif_draw.TOP)
				fx('y', y, inner.y + inner.height - height).start(function(): void {
					_arrow.orientation = uif_draw.BOTTOM;
				})
			else fx('y', y, _hidePos).start(function(): void {
				_arrow.orientation = uif_draw.TOP;
			})
		}
	}
}